package com.everflourish.yeah100.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.everflourish.yeah100.R;
import com.everflourish.yeah100.utils.constant.AnimEnum;

public class IntentUtil {
    public static final int OBJECTIVE_TOPICS_FLAG = 1;
    public static final int QUESTION_LIST_FLAG = 2;
    public static final int ERROR_QUESTION_LIST_FLAG = 3;

    public static final int CLASS_NAME_UPDATE_ACTIVITY = 1;
    public static final int CLASS_STUDENT_LIST_ACTIVITY = 2;
    public static final int JOIN_CLASS_ACTIVITY = 3;
    // 是否更新
    public static final String IS_UPDATE = "isUpdate";

    public static final String EXAMINATION_ID = "examinationId";
    public static final String IS_SHARE = "isShare";
    public static final String EXAMINATION = "FragmentExam.examination";
    public static final String QUESTIONLIST = "questionlist";
    public static final String QUESTIONLISTIMAGE = "questionlist.image";
    public static final String QUESTIONLISTIMAGEINDEX = "questionlist.image.index";
    public static final String FRIEND_ID = "friendId";
    public static final String FRIEND = "FragmentExam.friend";
    public static final String CLASS = "ClassManageActivity.clazz";
    public static final String CLASS_LIST = "CLASS_LIST";
    public static final String TEACHER_LIST = "TEACHER_LIST";
    public static final String CLASS_ID = "classId";
    public static final String QUESTION_IMAGE = "question_image";
    public static final String QUESTION_UPLOAD_URL = "question_upload_url";
    public static final String QUESTION_UPDATE = "question_update";
    public static final String QUESTION_IS_UPDATE = "QUESTION_IS_UPDATE";
    public static final String QUESTION_TAG_ID = "question_tag_id";
    public static final String QUESTION = "question";
    public static final String STUDENT_ANSWER = "student_answer";
    public static final String TOPIC = "topic";
    public static final String STANDARD_ANSWER = "standard_answer";
    public static final String SINGLE_UPLOAD = "single_upload";

    public static final int USER_UPDATE_ACTIVITY = 0x100;

    public static final int PHONE_UPDATE = 0x1001;
    public static final int MAIL_UPDATE = 0x1002;
    public static final int NICKNAME_UPDATE = 0x1003;
    public static final int MOTTO_UPDATE = 0x1004;

    public static final int ADD_FRIEND_ACTIVITY_FLAG = 0x300;
    public static final int LIST_FRIEND_ACTIVITY_FLAG = 0x301;

    public static final int E_CREATE_FLAG = 0x302;
    public static final int E_CREATE_FLAG2 = 0x304;
    public static final int E_CREATE_FLAG3 = 0x305;
    public static final int E_CLASS_LIST_FLAG = 0x303;
    // EMenuActivity跳转到EStudentAnswerActivity的请求码
    public static final int E_MENU_ACTIVITY_REQUEST_CODE = 0x304;
    public static final int SCAN_FRIEND_REQUEST_CODE = 0x305;

    public static final String FRIENDS = "friends";
    public static final String COUNTRY_RULES = "country_rules";
    public static final String COUNTRY_MODEL = "country_model";
    public static final String STUDENT_NUM = "student_num";
    public static final String OBJECTIVE_TOPICS = "ObjectiveTopics";
    public static final String QUESTIONS = "questions";
    public static final String POSITION = "position";
    public static final String IS_PUBLISH = "isPublish";

    public static final String FRIEND_IS_UPDATE = "friendIsUpdate";
    public static final String FLAG = "flag";

    //选中的共享老师
    public static final String CHECKED_TEACHERS = "checkedTeachers";

    public static <T> void startActivity(Activity srcAct, Class<T> decClazz,
                                         boolean isSrcFinish, AnimEnum animEnum) {
        Intent intent = new Intent(srcAct, decClazz);
        srcAct.startActivity(intent);
        startActivityTransition(srcAct, animEnum);
        if (isSrcFinish) {
            srcAct.finish();
        }
    }

    public static <T> void startActivity(Activity srcAct, Class<T> decClazz,boolean isSrcFinish) {
        Intent intent = new Intent(srcAct, decClazz);
        srcAct.startActivity(intent);
        if (isSrcFinish) {
            srcAct.finish();
        }
    }

    public static <T> void startActivity(Context context, Class<T> clazz) {
        Intent intent = new Intent(context, clazz);
        context.startActivity(intent);
    }

    public static <T> void finishActivity(Activity act, AnimEnum animEnum) {
        act.finish();
        closeActivityTransition(act, animEnum);
    }

    public static <T> void finishActivity(Activity act) {
        act.finish();
    }

    public static <T> void startService(Context context, Class<T> clazz) {
        Intent intent = new Intent(context, clazz);
        context.startService(intent);
    }

    public static <T> void stopService(Context context, Class<T> clazz) {
        Intent intent = new Intent(context, clazz);
        context.stopService(intent);
    }

    public static void startActivityTransition(Activity act, AnimEnum animEnum) {
        if (animEnum == AnimEnum.TRANSLATE_VERTICAL) { // 垂直移动
            act.overridePendingTransition(R.anim.translate_up,
                    R.anim.static_anim);
        } else if (animEnum == AnimEnum.TRANSLATE_HORIZONTAL) {
            act.overridePendingTransition(R.anim.translate_left,
                    R.anim.static_anim);
        } else if (animEnum == AnimEnum.ALPHA) { // 透明显示
            act.overridePendingTransition(R.anim.base_alpha_in,
                    R.anim.base_alpha_out);
        }
    }

    public static void closeActivityTransition(Activity act, AnimEnum animEnum) {
        if (animEnum == AnimEnum.TRANSLATE_VERTICAL) {
            act.overridePendingTransition(R.anim.static_anim,
                    R.anim.translate_down);
        } else if (animEnum == AnimEnum.TRANSLATE_HORIZONTAL) {
            act.overridePendingTransition(R.anim.static_anim,
                    R.anim.translate_right);
        }
    }
}
